package com.zcl.utils;

import java.util.List;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import com.zcl.adapter.UserInfoAdapter;
import com.zcl.bean.UserInfo;
import com.zcl.iweibo.LoginActivity;
import com.zcl.iweibo.R;

public class DialogFactory {
	/**
     * 创建alertDialog
     * 
     * @param title
     *            标题
     * @param message
     *            显示的消息
     * @param btnRes
     *            按钮上文字
     * @param clickListener
     *            点击按钮触发的函数
     * @return 返回alertDialog
     */
    public static Dialog createDialog(
            Context context, int title, int message, int btnRes, View.OnClickListener clickListener) {
    	View view = View.inflate(context, R.layout.authorize_dialog, null);
		view.findViewById(R.id.btn_confirm).setOnClickListener(clickListener);
		((TextView)view.findViewById(R.id.text_title)).setText(context.getString(title));
		((TextView)view.findViewById(R.id.text_content)).setText(context.getString(message));
		((TextView)view.findViewById(R.id.text_content)).setTextColor(Color.BLUE);
		((Button)view.findViewById(R.id.btn_confirm)).setText(context.getString(btnRes));
		Dialog dialog = new Dialog(context, R.style.auth_dialog);
		dialog.setContentView(view);
		
		return dialog;
    }
    
    public static Dialog createListDialog(Context context, List<UserInfo> users, OnItemClickListener listener){
    	View view = View.inflate(context, R.layout.user_select_dialog, null);
		ListView list = (ListView)view.findViewById(R.id.lv_user_list);
		UserInfoAdapter adapter = new UserInfoAdapter(context, users);
		list.setAdapter(adapter);
		list.setOnItemClickListener(listener);
		Dialog dialog = new Dialog(context, R.style.auth_dialog);
		dialog.setContentView(view);
		return dialog;
    }
    
    /**
     * 半透明进度条
     * @param context
     * @param tips
     * 			提示的信息
     * @return
     */
    public static Dialog createProgressDialog(Context context, String tips)
    {
    	LinearLayout mTipLayout;			// 显示提示信息的Layout
    	TextView mTipMessage;				// 显示提示信息
		mTipLayout = new LinearLayout(context);
		//mTipLayout.setBackgroundColor(Color.RED);
		
		/* 滚动圈和提示文字组成一个layout放在上部  */
		ProgressBar progressbar = new ProgressBar(context);	// 滚动进度条
		progressbar.setFocusable(false);
		progressbar.setIndeterminate(false);	// 进度条样式
		mTipMessage = new TextView(context);
		mTipMessage.setText(tips);
		
		LinearLayout.LayoutParams topLp;
		topLp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		topLp.setMargins(5, 5, 5, 5);
		topLp.gravity = Gravity.CENTER_VERTICAL;
		mTipLayout.addView(progressbar, topLp);
		mTipLayout.addView(mTipMessage, topLp);
		
		FrameLayout.LayoutParams fLp = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		fLp.gravity = Gravity.CENTER;

    	Dialog dialog = new Dialog(context, R.style.webview_loading_dialog);
		dialog.setContentView(mTipLayout, fLp);
    	return dialog;
    }
}
